<template>
  <div>
    <el-dialog title="新增商品" width="650px" :visible="visible"  @close="closeFn">
      <el-form :model="form">
        <el-form-item label="商品名称:" :label-width="formLabelWidth">
          <el-input  v-model="form.skuName" style="width: 396px"></el-input>
        </el-form-item>
        <el-form-item label="品牌：" :label-width="formLabelWidth">
          <el-input  v-model="form.brandName" style="width: 396px"></el-input>
        </el-form-item>
        <el-form-item label="商品价格(元):" :label-width="formLabelWidth">
           <el-input-number v-model="form.price" controls-position="right" style="width: 396px" @change="form.price-=0.5" :min="0" :max="10"/>
        </el-form-item>
        <el-form-item label="商品类型:" :label-width="formLabelWidth">
            <el-select v-model="form.classId" placeholder="请选择" style="width:80%">
          <el-option v-for="item in ''" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="规格:" :label-width="formLabelWidth">
          <el-input  v-model="form.unit" style="width: 396px"></el-input>
        </el-form-item>
        <el-form-item label="商品图片:" :label-width="formLabelWidth">
          <el-upload
          :v-model="form.image"
           :on-success="handleAvatarSuccess"
            action="https://likede2-admin.itheima.net/likede/api/vm-service/sku/fileUpload"
            list-type="picture-card"
          >
            <i class="el-icon-upload"></i>
          </el-upload>
          <el-dialog>
            <img width="100%" :src="form.image" alt="" />
          </el-dialog>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeFn">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
      <div class="el-upload__tip">
      支持扩展名:jpg、png,文件不得大于100kb
    </div>
    </el-dialog>
  </div>
</template>

<script>
import { addEquipments } from '@/api/zhang/equipment'
export default {
  data () {
    return {
      form: {
        skuName: '',
        skuImage: '',
        price: '0',
        classId: '0',
        unit: '0',
        image: ''
      },
      formLabelWidth: '120px'
    }
  },
  props: {
    visible: {
      type: Boolean,
      required: true
    }
  },
  methods: {
    handleAvatarSuccess (res) {
      console.log(1)
    },
    closeFn () {
      // console.log(1)
      this.$emit('update:visible', false)
    },
    async submit () {
      await addEquipments(this.form)
      // console.log(res)
      this.$message('添加成功')
      this.closeFn()
    }
  }
}
</script>

<style lang="scss" scoped>
  ::v-deep .el-upload--picture-card{
    background-color: #fbfdff;
    border: 1px dashed #c0ccda;
    border-radius: 6px;
    box-sizing: border-box;
    width: 84px;
    height: 84px;
    cursor: pointer;
    line-height: 84px;
    vertical-align: top;
  }
  .el-upload__tip {
    margin-left: 50px;
    font-size: 14px;
    color: #bac0cd;
}
</style>
